package com.ruoyi.aftersale.controller;

import com.ruoyi.aftersale.domain.DmsRepairOrder;
import com.ruoyi.aftersale.service.IDmsRepairOrderService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 维修工单Controller
 * 
 * @author liuchuanfa
 * @date 2024-03-13
 */
@RestController
@RequestMapping("/aftersale/repairOrder")
public class DmsRepairOrderController extends BaseController
{
    @Autowired
    private IDmsRepairOrderService dmsRepairOrderService;

    /**
     * 查询维修工单列表
     */
    @PreAuthorize("@ss.hasPermi('aftersale:repairOrder:list')")
    @GetMapping("/list")
    public TableDataInfo list(DmsRepairOrder dmsRepairOrder)
    {
        startPage();
        List<DmsRepairOrder> list = dmsRepairOrderService.selectDmsRepairOrderList(dmsRepairOrder);
        return getDataTable(list);
    }

    /**
     * 导出维修工单列表
     */
    @PreAuthorize("@ss.hasPermi('aftersale:repairOrder:export')")
    @Log(title = "维修工单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DmsRepairOrder dmsRepairOrder)
    {
        List<DmsRepairOrder> list = dmsRepairOrderService.selectDmsRepairOrderList(dmsRepairOrder);
        ExcelUtil<DmsRepairOrder> util = new ExcelUtil<DmsRepairOrder>(DmsRepairOrder.class);
        util.exportExcel(response, list, "维修工单数据");
    }

    /**
     * 获取维修工单详细信息
     */
    @PreAuthorize("@ss.hasPermi('aftersale:repairOrder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dmsRepairOrderService.selectDmsRepairOrderById(id));
    }

    /**
     * 新增维修工单
     */
    @PreAuthorize("@ss.hasPermi('aftersale:repairOrder:add')")
    @Log(title = "维修工单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmsRepairOrder dmsRepairOrder)
    {
        return toAjax(dmsRepairOrderService.insertDmsRepairOrder(dmsRepairOrder));
    }

    /**
     * 修改维修工单
     */
    @PreAuthorize("@ss.hasPermi('aftersale:repairOrder:edit')")
    @Log(title = "维修工单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmsRepairOrder dmsRepairOrder)
    {
        return toAjax(dmsRepairOrderService.updateDmsRepairOrder(dmsRepairOrder));
    }

    /**
     * 删除维修工单
     */
    @PreAuthorize("@ss.hasPermi('aftersale:repairOrder:remove')")
    @Log(title = "维修工单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dmsRepairOrderService.deleteDmsRepairOrderByIds(ids));
    }
}
